package com.qiwx.pigeon.activity.stock;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qiwx.pigeon.R;
import com.qiwx.pigeon.adapter.stock.StockManagerAdapter;
import com.qiwx.pigeon.base.BaseMVPActivity;
import com.qiwx.pigeon.presenter.StockPresenter;
import com.qiwx.pigeon.viewinterface.IStockView;
import com.qiwx.pigeon.widget.ArrowView;
import com.qiwx.pigeon.widget.itemderection.CustomGridItemDecoration;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @description
 * @Author qiwx
 * @Date 2020-03-24 14:59
 * 进销存管理
 **/
public class StockManagerActivity extends BaseMVPActivity<IStockView, StockPresenter> implements IStockView {

    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.title_return)
    ArrowView titleReturn;
    @BindView(R.id.title_right)
    TextView titleRight;
    @BindView(R.id.llTitle)
    LinearLayout llTitle;
    @BindView(R.id.txt_day_sales)
    TextView txtDaySales;
    @BindView(R.id.txt_month_sales)
    TextView txtMonthSales;
    @BindView(R.id.txt_month_profit)
    TextView txtMonthProfit;
    @BindView(R.id.txt_stock_amount)
    TextView txtStockAmount;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    List<StockManagerAdapter.StockItemBean> stocks = new ArrayList<>();
    StockManagerAdapter adapter;
    String[] names = new String[]{"出栏商品", "供应商", "客户", "货品", "支出", "收入", "收入统计", "支出统计", "库存统计"};
    int[] resIds = new int[]{
            R.drawable.stock_manager_clsp,
            R.drawable.stock_manager_gys,
            R.drawable.stock_manager_kehu,
            R.drawable.stock_manager_hp,
            R.drawable.stock_manager_zc,
            R.drawable.stock_manager_sr,
            R.drawable.stock_manager_srtj,
            R.drawable.stock_manager_zctj,
            R.drawable.stock_manager_kctj};
    Class[] types = new Class[]{
            GetOutManagerActivity.class,
            SupplierManagerActivity.class,
            CustomerManagerActivity.class,
            GoodsManagerActivity.class,
            null,
            null,
            null,
            null,
            null
    };


    @Override
    public StockPresenter createPresenter() {
        return new StockPresenter(new WeakReference(this));
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_stock_manager;
    }

    @Override
    public void initAfterOnCreate() {
        titleReturn.changeArrowLeft();
        titleContent.setText("库存管理");
        initStock();

    }

    private void initStock() {
        for (int i = 0; i < names.length; i++) {
            StockManagerAdapter.StockItemBean bean = new StockManagerAdapter.StockItemBean();
            bean.setName(names[i]);
            bean.setResId(resIds[i]);
            bean.setCla(types[i]);
            stocks.add(bean);
        }
        adapter = new StockManagerAdapter(R.layout.stock_manager_list_item, stocks);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
        recyclerview.setLayoutManager(gridLayoutManager);
        recyclerview.addItemDecoration(new CustomGridItemDecoration(1));
        recyclerview.setAdapter(adapter);
        adapter.setOnItemClickListener((adapter, view, pos) -> {
            if (stocks.get(pos).getCla() != null) {
                startActivity(new Intent(StockManagerActivity.this, stocks.get(pos).getCla()));
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.title_return})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_return:
                finish();
                break;
        }
    }
}
